<template>
  <div class="help-center">
    <!-- 顶部标题 -->
    <header class="page-header">
      <div class="header-content">
        <button @click="goBack" class="back-button">
          <i class="fas fa-arrow-left"></i>
        </button>
        <h1 class="page-title">帮助中心</h1>
        <div class="header-spacer"></div>
      </div>
    </header>

    <!-- 搜索栏 -->
    <div class="search-section">
      <div class="search-box">
        <i class="fas fa-search search-icon"></i>
        <input 
          v-model="searchKeyword" 
          type="text" 
          placeholder="搜索帮助内容..."
          class="search-input"
        >
      </div>
    </div>

    <!-- 常见问题分类 -->
    <div class="help-content">
      <div class="category-section" v-for="category in helpCategories" :key="category.id">
        <div class="category-header" @click="toggleCategory(category.id)">
          <div class="category-info">
            <div class="category-icon" :class="category.color">
              <i :class="category.icon"></i>
            </div>
            <div class="category-title">{{ category.title }}</div>
          </div>
          <i class="fas fa-chevron-down toggle-icon" :class="{ expanded: category.expanded }"></i>
        </div>
        
        <div class="category-content" v-show="category.expanded">
          <div 
            v-for="item in category.items" 
            :key="item.id"
            class="help-item"
            @click="showHelpDetail(item)"
          >
            <div class="help-question">{{ item.question }}</div>
            <i class="fas fa-chevron-right"></i>
          </div>
        </div>
      </div>

      <!-- 联系客服 -->
      <div class="contact-section">
        <div class="contact-card">
          <div class="contact-header">
            <div class="contact-icon">
              <i class="fas fa-headset"></i>
            </div>
            <div class="contact-info">
              <h3>联系客服</h3>
              <p>遇到问题？我们的客服团队随时为您服务</p>
            </div>
          </div>
          
          <div class="contact-methods">
            <button class="contact-method" @click="contactService('phone')">
              <i class="fas fa-phone"></i>
              <span>电话咨询</span>
            </button>
            
            <button class="contact-method" @click="contactService('chat')">
              <i class="fas fa-comment"></i>
              <span>在线客服</span>
            </button>
            
            <button class="contact-method" @click="contactService('email')">
              <i class="fas fa-envelope"></i>
              <span>邮件反馈</span>
            </button>
          </div>
        </div>
      </div>
    </div>

    <!-- 帮助详情弹窗 -->
    <div v-if="showDetail" class="detail-modal" @click="closeDetail">
      <div class="detail-content" @click.stop>
        <div class="detail-header">
          <h3>{{ selectedItem?.question }}</h3>
          <button @click="closeDetail" class="close-button">
            <i class="fas fa-times"></i>
          </button>
        </div>
        <div class="detail-body">
          <div class="answer-content" v-html="selectedItem?.answer"></div>
          
          <!-- 相关问题 -->
          <div v-if="selectedItem?.related?.length" class="related-questions">
            <h4>相关问题</h4>
            <div 
              v-for="related in selectedItem.related" 
              :key="related.id"
              class="related-item"
              @click="showRelatedItem(related)"
            >
              {{ related.question }}
            </div>
          </div>
        </div>
        
        <div class="detail-footer">
          <div class="feedback-section">
            <span>这个回答对您有帮助吗？</span>
            <div class="feedback-buttons">
              <button @click="giveFeedback(true)" class="feedback-btn helpful">
                <i class="fas fa-thumbs-up"></i> 有帮助
              </button>
              <button @click="giveFeedback(false)" class="feedback-btn not-helpful">
                <i class="fas fa-thumbs-down"></i> 没帮助
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, reactive, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'

export default {
  name: 'ClientHelp',
  setup() {
    const router = useRouter()
    const searchKeyword = ref('')
    const showDetail = ref(false)
    const selectedItem = ref(null)
    
    // 帮助分类数据
    const helpCategories = ref([
      {
        id: 1,
        title: '账户与登录',
        icon: 'fas fa-user-circle',
        color: 'blue',
        expanded: true,
        items: [
          {
            id: 101,
            question: '如何注册账户？',
            answer: '<p>注册账户非常简单：</p><ol><li>点击登录页面的"注册"按钮</li><li>输入手机号码</li><li>获取并输入验证码</li><li>设置登录密码</li><li>完善个人信息</li></ol><p>注册完成后即可正常使用平台服务。</p>',
            related: [
              { id: 102, question: '忘记密码怎么办？' },
              { id: 103, question: '如何修改个人信息？' }
            ]
          },
          {
            id: 102,
            question: '忘记密码怎么办？',
            answer: '<p>重置密码的步骤：</p><ol><li>在登录页面点击"忘记密码"</li><li>输入注册时的手机号</li><li>获取验证码</li><li>设置新密码</li></ol><p>如果手机号已更换，请联系客服协助处理。</p>',
            related: [
              { id: 101, question: '如何注册账户？' },
              { id: 103, question: '如何修改个人信息？' }
            ]
          },
          {
            id: 103,
            question: '如何修改个人信息？',
            answer: '<p>修改个人信息：</p><ol><li>进入"我的"页面</li><li>点击"个人设置"</li><li>选择要修改的信息项</li><li>保存修改</li></ol><p>注意：某些重要信息修改可能需要身份验证。</p>',
            related: []
          }
        ]
      },
      {
        id: 2,
        title: '案件管理',
        icon: 'fas fa-briefcase',
        color: 'green',
        expanded: false,
        items: [
          {
            id: 201,
            question: '如何查看案件进度？',
            answer: '<p>查看案件进度的方法：</p><ol><li>进入"我的案件"页面</li><li>选择要查看的案件</li><li>点击"案件进度"查看详细时间线</li></ol><p>您也可以在首页的案件概览中快速查看进度。</p>',
            related: []
          },
          {
            id: 202,
            question: '案件文档如何下载？',
            answer: '<p>下载案件文档：</p><ol><li>进入"案件文档"页面</li><li>找到需要的文档</li><li>点击"下载"按钮</li></ol><p>注意：只有状态为"可下载"的文档才能下载。</p>',
            related: []
          }
        ]
      },
      {
        id: 3,
        title: '律师预约',
        icon: 'fas fa-calendar-check',
        color: 'purple',
        expanded: false,
        items: [
          {
            id: 301,
            question: '如何预约律师咨询？',
            answer: '<p>预约律师咨询：</p><ol><li>进入"律师预约"页面</li><li>选择合适的律师</li><li>选择咨询时间</li><li>填写咨询内容</li><li>提交预约申请</li></ol><p>律师确认后您会收到通知。</p>',
            related: []
          },
          {
            id: 302,
            question: '预约费用如何计算？',
            answer: '<p>预约费用说明：</p><ul><li>首次咨询：免费30分钟</li><li>后续咨询：按律师收费标准</li><li>紧急咨询：可能产生加急费用</li></ul><p>具体费用在预约时会明确显示。</p>',
            related: []
          }
        ]
      },
      {
        id: 4,
        title: '积分与奖励',
        icon: 'fas fa-gift',
        color: 'orange',
        expanded: false,
        items: [
          {
            id: 401,
            question: '如何获得积分？',
            answer: '<p>获得积分的方式：</p><ul><li>完成案件咨询：+20分</li><li>完善个人信息：+10分</li><li>推荐朋友注册：+50分</li><li>参与平台活动：不定期奖励</li></ul><p>积分可在积分商城兑换礼品。</p>',
            related: []
          },
          {
            id: 402,
            question: '积分如何使用？',
            answer: '<p>积分使用方法：</p><ol><li>进入"积分商城"</li><li>浏览可兑换的商品</li><li>选择心仪的商品</li><li>确认兑换</li></ol><p>兑换成功后，礼品将邮寄到您的地址。</p>',
            related: []
          }
        ]
      }
    ])
    
    // 切换分类展开状态
    const toggleCategory = (categoryId) => {
      const category = helpCategories.value.find(c => c.id === categoryId)
      if (category) {
        category.expanded = !category.expanded
      }
    }
    
    // 显示帮助详情
    const showHelpDetail = (item) => {
      selectedItem.value = item
      showDetail.value = true
    }
    
    // 显示相关问题
    const showRelatedItem = (relatedItem) => {
      // 在所有分类中查找相关问题的完整信息
      for (const category of helpCategories.value) {
        const fullItem = category.items.find(item => item.id === relatedItem.id)
        if (fullItem) {
          selectedItem.value = fullItem
          break
        }
      }
    }
    
    // 关闭详情弹窗
    const closeDetail = () => {
      showDetail.value = false
      selectedItem.value = null
    }
    
    // 反馈
    const giveFeedback = (helpful) => {
      const message = helpful ? '感谢您的反馈！' : '我们会继续改进，谢谢您的建议。'
      alert(message)
    }
    
    // 联系客服
    const contactService = (method) => {
      switch (method) {
        case 'phone':
          alert('客服电话：400-123-4567\n服务时间：9:00-18:00')
          break
        case 'chat':
          alert('正在为您转接在线客服...')
          break
        case 'email':
          alert('客服邮箱：service@example.com\n我们会在24小时内回复您的邮件')
          break
      }
    }
    
    // 返回上一页
    const goBack = () => {
      router.go(-1)
    }
    
    return {
      searchKeyword,
      showDetail,
      selectedItem,
      helpCategories,
      toggleCategory,
      showHelpDetail,
      showRelatedItem,
      closeDetail,
      giveFeedback,
      contactService,
      goBack
    }
  }
}
</script>

<style scoped>
.help-center {
  min-height: 100vh;
  background: #f8f9fa;
}

/* 页面头部 */
.page-header {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
}

.back-button {
  background: none;
  border: none;
  font-size: 18px;
  color: #374151;
  cursor: pointer;
  padding: 8px;
  margin-left: -8px;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0;
}

.header-spacer {
  width: 34px;
}

/* 搜索栏 */
.search-section {
  background: white;
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.search-box {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 16px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 48px;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  font-size: 14px;
  background: #f9fafb;
}

.search-input:focus {
  outline: none;
  border-color: #3b82f6;
  background: white;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 帮助内容 */
.help-content {
  padding: 20px;
}

/* 分类区域 */
.category-section {
  background: white;
  border-radius: 12px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.category-header:hover {
  background: #f9fafb;
}

.category-info {
  display: flex;
  align-items: center;
}

.category-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
}

.category-icon.blue {
  background: #dbeafe;
  color: #1d4ed8;
}

.category-icon.green {
  background: #dcfce7;
  color: #16a34a;
}

.category-icon.purple {
  background: #f3e8ff;
  color: #7c3aed;
}

.category-icon.orange {
  background: #fed7aa;
  color: #ea580c;
}

.category-title {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
}

.toggle-icon {
  color: #9ca3af;
  transition: transform 0.2s ease;
}

.toggle-icon.expanded {
  transform: rotate(180deg);
}

/* 分类内容 */
.category-content {
  border-top: 1px solid #f3f4f6;
}

.help-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.help-item:last-child {
  border-bottom: none;
}

.help-item:hover {
  background: #f9fafb;
}

.help-question {
  font-size: 14px;
  color: #374151;
  flex: 1;
}

.help-item i {
  color: #9ca3af;
  font-size: 12px;
}

/* 联系客服 */
.contact-section {
  margin-top: 24px;
}

.contact-card {
  background: white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.contact-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.contact-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
}

.contact-icon i {
  font-size: 20px;
  color: white;
}

.contact-info h3 {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 4px 0;
}

.contact-info p {
  font-size: 14px;
  color: #6b7280;
  margin: 0;
}

.contact-methods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.contact-method {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 12px;
  color: #374151;
}

.contact-method:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.contact-method i {
  font-size: 18px;
  margin-bottom: 8px;
  color: #667eea;
}

/* 详情弹窗 */
.detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.detail-content {
  background: white;
  border-radius: 16px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 0;
}

.detail-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
  margin: 0;
  flex: 1;
  padding-right: 16px;
}

.close-button {
  background: none;
  border: none;
  font-size: 18px;
  color: #9ca3af;
  cursor: pointer;
  padding: 8px;
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.answer-content {
  font-size: 14px;
  line-height: 1.6;
  color: #374151;
}

.answer-content p {
  margin-bottom: 16px;
}

.answer-content ol,
.answer-content ul {
  margin-bottom: 16px;
  padding-left: 20px;
}

.answer-content li {
  margin-bottom: 8px;
}

.related-questions {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid #f3f4f6;
}

.related-questions h4 {
  font-size: 16px;
  font-weight: 600;
  color: #111827;
  margin: 0 0 16px 0;
}

.related-item {
  padding: 12px 16px;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  font-size: 14px;
  color: #3b82f6;
}

.related-item:hover {
  background: #f3f4f6;
}

.detail-footer {
  padding: 24px;
  border-top: 1px solid #f3f4f6;
}

.feedback-section {
  text-align: center;
}

.feedback-section span {
  font-size: 14px;
  color: #6b7280;
  display: block;
  margin-bottom: 16px;
}

.feedback-buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.feedback-btn {
  padding: 8px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.feedback-btn.helpful:hover {
  border-color: #16a34a;
  color: #16a34a;
}

.feedback-btn.not-helpful:hover {
  border-color: #dc2626;
  color: #dc2626;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .help-content {
    padding: 16px;
  }
  
  .contact-methods {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .contact-method {
    flex-direction: row;
    justify-content: flex-start;
    padding: 12px 16px;
  }
  
  .contact-method i {
    margin-bottom: 0;
    margin-right: 12px;
  }
}

@media (max-width: 480px) {
  .header-content {
    padding: 12px 16px;
  }
  
  .search-section {
    padding: 12px 16px;
  }
  
  .category-header {
    padding: 16px;
  }
  
  .help-item {
    padding: 12px 16px;
  }
  
  .detail-modal {
    padding: 16px;
  }
  
  .detail-header {
    padding: 20px 20px 0;
  }
  
  .detail-body {
    padding: 20px;
  }
  
  .detail-footer {
    padding: 20px;
  }
}
</style>
